/**
 * @Author: lusx
 * @Date:   19-04-2019 03:49:27
 * @Project: Govern督办
 * @Last modified by:   lusx
 * @Last modified time: 19-04-2019 05:30:00
 */
import React from 'react';
import { observer } from 'mobx-react';
import { WeaRichText, WeaLocaleProvider } from 'ecCom';
import { Row, Col, Button, Slider } from 'antd';
import * as Util from '../../../util/index';
import BtnType from '../../../util/btnType';
import FormBottom from './FormBottom'
import { Condition } from '../list/listCondition';
import Dict from '../dialog/wea-comment-dict';
const mirror = Dict.bottomBarMirror;
const getLabel = WeaLocaleProvider.getLabel;
import { WeaTableNew } from 'comsMobx';
const WeaTable = WeaTableNew.WeaTable;

@observer
export default class Normal extends React.Component {
    constructor(props) {
        super(props);
    }

    reRenderColumns(columns) {
        columns.forEach(c => {
            c.render = function (text, record) {
                let valueSpan = record[c.dataIndex + "span"] !== undefined ? record[c.dataIndex + "span"] : record[c.dataIndex];
                return <span className='g-table-rerender' dangerouslySetInnerHTML={{ __html: valueSpan }}></span>
            }
        })
        return columns;
    }

    render() {
        const { modelType, store, btnAddClick, marks, changeHandle } = this.props;
        const { form, formB, visibleTip, percent, richTextShowType,loading,tableStoreLog } = store;
        return (
            <div>
                {
                    BtnType.checkShowModel(modelType) &&
                    <div style={{ height: '100%' }}>
                        {
                            (modelType == BtnType.BTN_REPORT || modelType == BtnType.BTN_URGENT || modelType == BtnType.BTN_INSTRUCT) &&
                            <div>
                                <Condition ecId={`${this && this.props && this.props.ecId || ''}_Condition@72372y`} listStore={store} form={form} ></Condition>
                            </div>
                        }
                        {modelType == BtnType.BTN_SPLIT && <Condition ecId={`${this && this.props && this.props.ecId || ''}_Condition@52ssoy`} listStore={store} form={form} listStore2={store}></Condition>}
                        {modelType == BtnType.BTN_CHANGE && <Condition ecId={`${this && this.props && this.props.ecId || ''}_Condition@3eeq28`} listStore={store} form={form} listStore2={store}></Condition>}
                        {
                            modelType == BtnType.BTN_SPLIT &&
                            <div style={{ position: "relative" }}>
                                <div style={{ position: "absolute", right: "35px", zIndex: "1", top: "-5px" }}>
                                    <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@xhgi1x`} type="primary" shape="circle" icon="plus" onClick={btnAddClick.bind(this, -1)} />
                                </div>
                                <FormBottom ecId={`${this && this.props && this.props.ecId || ''}_FormBottom@zzf364`} listStoreB={store} formB={formB} style={{ marginTop: "10" }} visibleTip={visibleTip} listStore2={store}></FormBottom>
                            </div>
                        }
                        {
                            (BtnType.checkShowRithtext(modelType)) &&
                            <div className="a1a1" style={{ height: '100%' }}>
                                {
                                    modelType == BtnType.BTN_REPORT && <div style={{ margin: "10px 50px 0 50px", marginRight: "80px" }}>
                                        <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@l2d00k`}>
                                            <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@qleb77`} span={4}>
                                                <span>{getLabel('383349,388385', "任务进度")}:</span>
                                            </Col>
                                            <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@223p1l`} span={20}>
                                                <div style={{ width: "60%" }}>
                                                    <Slider ecId={`${this && this.props && this.props.ecId || ''}_Slider@92u4xm`} marks={marks} step={1} value={percent} onChange={(v) => { changeHandle(v) }} />
                                                </div>
                                            </Col>

                                        </Row>
                                    </div>
                                }
                                <div style={{ margin: "50px" }} className="asd">
                                    <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@e7tczu`}>
                                        <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@0gitf3`} span={4}>
                                            <span>{richTextShowType == "0" ? getLabel('345,93', "内容编辑") : getLabel('345', "内容")}:</span>
                                        </Col>
                                        <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@bj5933`} span={20}>
                                            <GetRichText ecId={`${this && this.props && this.props.ecId || ''}_GetRichText@ys874r`} richStore={store} />
                                        </Col>
                                    </Row>
                                </div>
                            </div>
                        }
                        {modelType == BtnType.BTN_SHOWULOGCHANGE && 
                        <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@v7n4sw`}
                            dragColumns = '0'
                            comsWeaTableStore={tableStoreLog}
                            hasOrder={true}
                            needScroll={true}
                            getColumns={c => this.reRenderColumns(c)}
                        />}
                    </div>
                }
            </div>
        )
    }
}

@observer
class GetRichText extends React.Component {
    render() {
        const { basicToolBar, bottomConfigData, content, changeRichText, memoryValue, richTextShowType, loading } = this.props.richStore;
        let bottomBarConfig = [];
        let uploadUrl = '';
        bottomConfigData && bottomConfigData.appList.map(cg => {
            cg.name === 'dialogs' && cg.items.map(item => {
                let obj = {
                    isBlog: true,
                    name: 'Browser',
                    show: <div className="wea-cb-item">
                        <span className={`wea-cbi-icon ${mirror[item].icon}`} />
                        <span className="wea-cbi-text">{mirror[item].nameFunc()}</span>
                    </div>,
                    type: mirror[item].type,
                    title: mirror[item].nameFunc(),
                    isSingle: item === 'Templet',
                };
                if (item === 'Templet') obj.onToolsChange = this.onTempletChange
                bottomBarConfig.push(obj);
            })
            cg.name === 'uploads' && cg.items.map(item => {
                bottomBarConfig.push({
                    isBlog: true,
                    name: 'Upload',
                    show: <div className="wea-cb-item">
                        <span className='wea-cbi-icon icon-blog-Enclosure' />
                        <span className="wea-cbi-text">{getLabel(156, "附件")}</span>
                    </div>,
                    uploadId: 'webo_edit',
                    uploadUrl: `${item.Attachment.uploadUrl}?category=${item.Attachment.position}`,
                    category: item.Attachment.position,
                    maxUploadSize: item.Attachment.maxSize,
                    style: { display: "inline-block" }
                })
                uploadUrl = `${item.Attachment.uploadUrl}?category=${item.Attachment.position}`;
            })
        })
        return (
            <div>
                {richTextShowType == "0"  && <WeaRichText ecId={`${this && this.props && this.props.ecId || ''}_WeaRichText@30m7bw`}
                    ckConfig={basicToolBar}
                    bottomBarConfig={bottomBarConfig}
                    ls={false}
                    ref={ref => { this.props.richStore.weaRichRef = ref }}
                    bootomBarStyle={{}}
                    onToolsChange={Util.transfStr}
                    value={memoryValue}
                />}
                {richTextShowType == "1" && <div dangerouslySetInnerHTML={{ __html: memoryValue }}></div>}
            </div>
        )
    }
}
